package Lecture9;

import java.util.Arrays;
import java.util.Scanner;

public class ShopTask {

	private static Scanner sc;

	public static void main(String[] args)
	{
		Scanner sc = new Scanner (System.in);
		int num = 1;
		int[] total = new int[0];
		int info = 0;
		
		while(num != 0)
		{
		System.out.println( "For adding sum in shop press 1. \n" +
							"For total sum information press 2. \n" +
                  		    "For exit press 0. \n");
		
		num = sc.nextInt();
		
		
			if (num == 1)
			{
				total = addingSum(total);

			}
				
			if (num == 2)
			{
			System.out.println(returnInformation(info, total));
			
			}
				
			if (num != 1 && num != 2 && num != 0)
			{
				System.out.println("Wrong number!"); 
				continue;
			}
			
		}
		
		System.out.println("Exit!");
	}

	public static int[] addingSum ( int[] total)
	{
		Scanner sc = new Scanner (System.in);
		
		System.out.println("Enter the number of the shop you want to add sum ");
		int shop = sc.nextInt();
		
		System.out.println("Enter the sum you want to add in shtop " + shop);
		int sum = sc.nextInt();
		
		int[] array = new int[total.length + 1];
		
		for(int i = 0; i < total.length; i++)
		{
			array[i] = total[i];
		}
		
		array[array.length-1] = sum;
		total = array;
		
		return total;
	}
	
	
	public static int returnInformation ( int info, int[] total)
	{
		System.out.println("Enter between which numbers you want to get the sum information. ");
		
		Scanner sc = new Scanner (System.in);
		int first = sc.nextInt();
		int last = sc.nextInt();
		info = 0;
		
		for (int i = first-1; i < last; i++)
		{
			info += total[i]; 
			
		}
				
		return info;
	}
	
	
	
	
}
